let paramsObj = new URLSearchParams(location.search);
let pid = paramsObj.get("pid");
console.log(pid);

let main = document.querySelector('.main')
axios
    .get(detailAPI, {
        params: {
            id: pid,
        },
    })
    .then((res) => {
        let pobj = res.data.data;
        console.log(pobj);

        let html = `
        <div class="main-l">
            <img src="${pobj.pimg}" alt="" />
        </div>
        <div class="main-r">
            <div class="main-r-t">
                <h2>${pobj.pname}</h2>
                <p>
                    <em>「今日上午10点再次开售；最高享12期免息；标配不提供充电器和数据线，如需请选择套装版」</em
            ><b
              >${pobj.pdesc}</b
            >
          </p>
          <span>小米自营</span>
          <a href="">${pobj.pprice}</a>
        </div>
        <div class="main-r-c">
            <p>
                <span>河南 郑州市 高新区 枫杨街道</span><a href="">修改</a
            ><em>有现货</em>
                </p>
                <h3>选择版本</h3>

                <ul>
                    <li>8GB+128GB</li>
                    <li>8GB+256GB</li>
                    <li>12GB+256GB</li>
                </ul>

                <h3>选择颜色</h3>

                <ul>
                    <li>黑色</li>
                    <li>蓝色</li>
                    <li>白色</li>
                    <li>粉色</li>
                </ul>
                <h3>选择套餐</h3>
                <ul>
                    <li>标准版</li>
                    <li>套装版</li>
                </ul>
            </div>
            <div class="main-r-b">
                <p><span>小米11 8GB+128GB 黑色</span><em>${pobj.pprice}元</em></p>
                <h2>总计:${pobj.pprice}元</h2>
            </div>
            <div class="web">
                <button id='btn0'>加入购物车</button>
                <a href="">喜欢</a>
        </div>
    </div>
                      `;

        main.innerHTML = html;

        let btn = document.querySelector('#btn0')
        console.log(btn);
        btn.onclick = function() {
            let paramsObj = new URLSearchParams(location.search);
            let pid = paramsObj.get("pid");
            let uid = localStorage.getItem("uid");
            let pnum = 1
            let params = {
                pid,
                uid,
                pnum,
            };
            axios
                .get(cartAddAPI, {
                    params,
                })
                .then((res) => {
                    alert(res.data.msg);
                    location.href = "index.html";
                });
        }
    });